import { reqgetCategoryList, reqgetBannerList, reqgetFloorList } from '../api';

const state = {
  //state中的数据根据服务器返回值进行初始化
  categoryList: [],
  bannerList: [],
  floorList: []
};
//第三步：在mutation中修改state数据
//mutation是唯一修改state的地方
const mutations = {
  CATEGORYLIST(state, categoryList) {
    state.categoryList = categoryList;
  },
  BANNERLIST(state, bannerList) {
    state.bannerList = bannerList;
  },
  FLOORLIST(state, floorList) {
    state.floorList = floorList;
  }
};
//第二步：在action中异步获取服务器数据
//action是用户处理派发action的地方，可以书写异步语句、自己逻辑的地方
const actions = {
  //通过API里面的接口函数调用，向服务器发请求，获取服务器的数据
  async getCategoryList({ commit }) {
    let result = await reqgetCategoryList();
    if (result.code == 200) {
      commit("CATEGORYLIST", result.data);
    }
  },
  async getBannerList({ commit }) {
    let result = await reqgetBannerList();
    if (result.code == 200) {
      commit("BANNERLIST", result.data);
    }
  },
  async getFloorList({ commit }) {
    let result = await reqgetFloorList();
    if (result.code == 200) {
      commit("FLOORLIST", result.data);
    }
  }
};
//计算属性
const getters = {};
export default {
  state,
  mutations,
  actions,
  getters,
};
